package org.itboys.mobile.controller.web;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.entity.mongo.SundayApply;
import org.itboys.mobile.service.mongo.web.SundayApplyService;
import org.itboys.mobile.util.ResponseMessage;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author：贾琦磊
 * @Date：2018/7/16
 * @Description：web端报名信息接口
 */
@Controller
@RequestMapping("/sunday/web/apply")
public class SundayApplyController extends BaseController{

    @Autowired
    private SundayApplyService applyService;

    @RequestMapping("/index")
    public String index(HttpServletRequest request, HttpServletResponse response){
            return "sunday/apply/index";
    }

    @RequestMapping("/select")
    public void select(HttpServletRequest request, HttpServletResponse response){
        try {
            PageResult<SundayApply> result= applyService.select(request);
            JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),response);
        } catch (Exception e) {
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }
    }

    @RequestMapping("/processed")
    public void processed(HttpServletRequest request, HttpServletResponse response
    , @RequestParam("id")Long id){
        try {
            applyService.processed(id);
            ResponseMessage.success();
        } catch (Exception e) {
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,"error");
        }
    }
    @RequestMapping("/delete")
    public void delete(@RequestParam("id")Long id){
        try {
            applyService.delete(id);
            ResponseMessage.success();
        } catch (Exception e) {
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,"error");
        }
    }
}
